const mongoose = require('./db');

const schema = mongoose.Schema({
    comment: String,
    createTime: {
        type: Date,
        default: Date.now,
        get: (createTime) => {
            return `
            ${createTime.getFullYear()}-${createTime.getMonth()+1}-${createTime.getDate()}
				${createTime.getHours()}:${createTime.getMinutes()}
            `;
        }
    },
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'users'
    },
    article: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'articles'
    }
}, {
    collection: 'comments'
});

const commentsModel = mongoose.model('comments', schema);

module.exports = commentsModel;